//请求业务
'use strict';
import React from 'React';
import {Platform} from 'react-native';
import ApiConfig from '../configs/ApiConfig';


var MyHeader = new Header();
MyHeader.append('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0 HXMall Android');

var MyInit_Get = {
              method: 'GET',
              headers: MyHeader,
              mode: 'cors',
              cache: 'default'
};

//单例
function ApiClient(){
  if (typeof ApiClient.instance === 'object') {
    return ApiClient.instance;
  }
  ApiClient.instance = this;
}

//轮播图片数据
ApiClient.prototype.HomeSliderDataFetch = function(successCallback,errorCallback){
  let URL = ApiConfig.ADSliderUrl;
  let request_get = new Request(URL,MyInit_Get);
  console.log("js_Tag","start HomeSliderDataFetch");
  fetch(request_get).then(function(res) {
          if (res.ok) {
            console.log("js_Tag","HomeSliderDataFetch   ok");
            res.json().then(function(data) {
               if (data.length >= 1) {
               successCallback && successCallback(data);
             }else {
               let eMsg = {
                 code:500,
                 message:'data is null'
               };
               errorCallback && errorCallback(eMsg);
             }
            });
          } else {
            let eMsg = {
              code:501,
              message:'request fail'
            };
            errorCallback && errorCallback(eMsg);
          }
        }, function(e) {
          let eMsg = {
            code:502,
            message:'request exception'
          };
          errorCallback && errorCallback(eMsg);
        });

};
